package cn.icatw.leetcode.editor.cn.juc;

/**
 * @author 王顺 762188827@qq.com
 * @apiNote
 * @since 2024/8/14
 */
public class TicketDemo {
    private static final Object lock = new Object();
    private static int ticket = 100;

    public static synchronized void sale() {
        //synchronized (lock) {
            if (ticket > 0) {
                ticket--;
                System.out.println("卖出一张票，剩余：" + ticket);
            }
        //}

    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(TicketDemo::sale).start();
        }
    }
}
